using System;
using Godot;

namespace GoGameClient.script.node.letter;

public partial class TimeControl : Control
{
    // Called when the node enters the scene tree for the first time.
    private TextureRect[] _timeRects = new TextureRect[6];
    private string _currentTime;

    public override void _Ready()
    {
        for (var i = 0; i < 6; i++)
        {
            _timeRects[i] = GetNode<TextureRect>($"{i}");
        }
    }

    // 新增一个方法用于更新时间显示
    private void UpdateTimeDisplay()
    {
        var date = DateTime.Now.ToString("HH:mm:ss");
        if (date == _currentTime)
            return;
        _currentTime = date;
        var charArray = _currentTime.Replace(":", "").ToCharArray();
        for (var i = 0; i < _timeRects.Length; i++)
        {
            _timeRects[i].Texture = GD.Load<Texture2D>($"res://resources/Ui/common/{charArray[i]}.png");
        }
    }

    // Called every frame. 'delta' is the elapsed time since the previous frame.
    public override void _Process(double delta)
    {
        UpdateTimeDisplay();
    }
}